﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Regions;
using DashboardModule.Services.Temp;
using DashboardModule.ViewModels;

namespace DashboardModule.Views
{
    /// <summary>
    /// Interaction logic for TempReportsView.xaml
    /// </summary>
    public partial class TempReportsView : UserControl, INavigationAware
    {
        private TempReportsViewModel Model;
        private readonly ITempReportsService _service;

        public TempReportsView(ITempReportsService service)
        {
            InitializeComponent();

            _service = service;
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return false; //throw new NotImplementedException();
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
            //throw new NotImplementedException();
        }

        public async void OnNavigatedTo(NavigationContext navigationContext)
        {
            //throw new NotImplementedException();

            this.itemsGrid.Visibility = System.Windows.Visibility.Hidden;
            this.progressBorder.Visibility = System.Windows.Visibility.Visible;
            this.progressRing.IsActive = true;

            await Task.Run(() => Model = _service.GetViewModel());

            this.itemsGrid.Visibility = System.Windows.Visibility.Visible;
            this.progressBorder.Visibility = System.Windows.Visibility.Hidden;
            this.progressRing.IsActive = false; ;

            this.DataContext = Model;
        }

        private  async void weeklyReportButton_Click(object sender, RoutedEventArgs e)
        {
            Model.StartDate = DateTime.Parse(this.startDateTextBlock.Text);
            Model.EndDate = DateTime.Parse(this.endDateTextBlock.Text);

            // Binding the dates to the datepicker is not working :/

            await Task.Run(() => _service.WeeklyActivityReport(Model.SelectedUser, Model.StartDate, Model.EndDate));
        }

        private async void projectSummaryButton_Click(object sender, RoutedEventArgs e)
        {
            await Task.Run(() => _service.ProjectSummary(Model.SelectedUser));
        }

        private async void projectReport_Click(object sender, RoutedEventArgs e)
        {
            await Task.Run(() => _service.ProjectDetails(Model.SelectedUser, Model.SelectedProject));
        }
    }
}
